Skip to content

Conversation

@deepaksakpal
Copy link

Added SelectedItemChanged event so that user can get the selected row from the list.

Added SelectedItemChanged event
<local:MainViewModel />
</ContentPage.BindingContext>
<local:BindableStackLayout
<local:BindableStackLayout
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If possible, it will make sense to add a sample of binding to SelectedItem.
It will require to implement a INotifyPropertyChanged on the VM level and add public property with getter and setter.

if (layout == null)
return;

foreach (var child in layout.Children)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need to add a TapGestureRecognizer to sub views?


protected readonly ICommand ItemSelectedCommand;

protected void AddGesture(View view, TapGestureRecognizer gesture)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Why protected? In my opinion should be private.
  2. There are different types of Gestures, it will make sense to rename the method to AddTapGestureRecognize.

P.S.: In order to keep the code style consistent the access modifier private should be removed as it is a default access modifier.

return view;
}

protected readonly ICommand ItemSelectedCommand;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why protected? In my opinion should be private and since it is a field it should be declared before constructor.

P.S.: In order to keep the code style consistent the access modifier private should be removed as it is a default access modifier.


void PopulateHeader() => header.Text = Title;

protected virtual View GetItemView(object item)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why protected and virtual? In my opinion should be just private.

P.S.: In order to keep the code style consistent the access modifier private should be removed as it is a default access modifier.

itemsView.SetSelectedItem(newValue);
}

protected virtual void SetSelectedItem(object selectedItem)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why protected and virtual? In my opinion should be just private.

P.S.: In order to keep the code style consistent the access modifier private should be removed as it is a default access modifier.

if (newValue == oldValue)
return;

itemsView.SetSelectedItem(newValue);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method SetSelectedItem(..) can be replaced with a single line of code SelectedItemChanged?.Invoke(...)

propertyChanged: OnSelectedItemChanged
);

private static void OnSelectedItemChanged(BindableObject bindable, object oldValue, object newValue)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to keep the code style consistent the access modifier private should be removed as it is a default access modifier.

returnType: typeof(object),
declaringType: typeof(BindableStackLayout),
defaultValue: null,
defaultBindingMode: BindingMode.OneWay,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BindingMode should be set to BindingMode.TwoWay.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants